home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
DEV
/
A-B
/
add images.cpt
/
Result.c
< prev
next >
Wrap
Text File
|
1989-06-22
|
19KB
|
660 lines
/* ===================================
File: Result.c
Function: Handle all operations for this window
History: 4/27/89 Original by Prototyper.
================================= */
#include "Result.h"
#include "pix_io.h"
#include <ColorToolbox.h>
#include <IM5protos.h>
WindowPtr Result_Window; /* Window pointer -- global variable */
Rect result_rect; /* top/bottom/left/right coords of current result image */
static short off_top, off_left; /* offsets on the window from scrolling */
extern short pix_zoom;
extern PaletteHandle mypalette;
extern RGBColor BlackRGB, whiteRGB, grayRGB;
static Str255 filename;
PicHandle result_pic;
CGrafPtr result_bmap;
static void draw_result( void );
static void HandleVScrollBar (short code, short Start, short Stop,
short Increment, short LIncrement,
ControlHandle theControl, Point myPt);
static void HandleHScrollBar (short code, short Start, short Stop,
short Increment, short LIncrement,
ControlHandle theControl, Point myPt);
static void Do_A_ScrollBar (short code, ControlHandle theControl, Point myPt);
/* *********************************** */
/* These are the other includes for general routines */
#include <Strings.h>
extern char *strcpy (Str255 *, char *); /* LSC string prototype */
/* *********************************** */
#define TRUE 1
#define FALSE 0
#define NIL 0
/* *********************************** */
/* Scrollbar ID */
#define I_Vertical_Scroll_bar 29
/* Scrollbar ID */
#define I_Horiz_Scroll_bar 28
#define min_scroll 1
#define max_scroll 100
#define small_step 1
#define large_step 10
static Rect tempRect, temp2Rect; /* Temporary rectangle */
static short Index; /* For looping */
static ControlHandle CtrlHandle; /* Control handle */
static ControlHandle ScrollHHandle, ScrollVHandle; /* Scrolling Control*/
static Str255 sTemp; /* Get text entered, temp holding */
static OSErr MyErr; /* General OS error return */
static ControlHandle C_Vertical_Scroll_bar; /* Scroll bar Control Handl*/
static ControlHandle C_Horiz_Scroll_bar; /* Scroll bar Control Handl*/
/* ====================================== */
/* Initialize us so all our routines can be activated */
void Init_Result ()
{
Result_Window = NIL; /* Make sure other routines know we are not */
result_rect.top = 0;
result_rect.bottom = all_my_colors;
result_rect.left = 0;
result_rect.right = 300;
}
/* ================================= */
void activate_result (whichWindow, modifiers)
WindowPtr whichWindow;
long modifiers;
{
WindowPtr SavePort;
GetPort (&SavePort);
if ( modifiers & activeFlag != 0 )
{
SelectWindow(whichWindow);
SetPort(whichWindow);
ShowControl (ScrollHHandle);
ShowControl (ScrollVHandle);
DrawGrowIcon( whichWindow );
DrawControls( whichWindow );
}
else
{
SetPort(whichWindow);
HideControl (ScrollHHandle);
HideControl (ScrollVHandle);
DrawGrowIcon( whichWindow );
DrawControls( whichWindow );
}
SetPort(SavePort);
}
typedef WStateData **WStateHandle;
void zoom_result( where, whichWindow, code )
Point * where;
WindowPeek whichWindow;
short code;
{
Point myPt;
WStateHandle WState;
SetPort (whichWindow);
if ( whichWindow->dataHandle != NIL )
{
WState = (WStateHandle) whichWindow->dataHandle;
(**WState).stdState = result_rect;
(**WState).stdState.top += 40;
(**WState).stdState.left += 2;
(**WState).stdState.right += 2;
(**WState).stdState.bottom += 40;
if ( (**WState).stdState.bottom > screenBits.bounds.bottom )
{
(**WState).stdState.bottom = screenBits.bounds.bottom - 5;
}
if ( (**WState).stdState.right > screenBits.bounds.right )
{
(**WState).stdState.right = screenBits.bounds.right - 5;
}
}
myPt = *where; /* Get mouse position */
GlobalToLocal (&myPt); /* Make it relative */
if (TrackBox (whichWindow, myPt, code) == TRUE)
{
EraseRect( &whichWindow->port.portRect );
ZoomWindow (whichWindow, code, TRUE);
InvalRect (&whichWindow->port.portRect);
}
Resized_Result( Result_Window );
}
void grow_result( where, whichWindow )
Point * where;
WindowPtr whichWindow;
{
Point myPt;
Rect OldRect;
long mResult;
SetPort (whichWindow);
myPt = *where;
GlobalToLocal (&myPt); /* Make it relative */
OldRect.left = whichWindow->portRect.left;
OldRect.right = whichWindow->portRect.right;
OldRect.top = whichWindow->portRect.top;
OldRect.bottom = whichWindow->portRect.bottom;
mResult = GrowWindow (whichWindow, *where, &result_rect);
SizeWindow (whichWindow, LoWord (mResult),
HiWord (mResult), TRUE);
Resized_Result(Result_Window);
}
/* We were resized or zoomed, update the scrolling scrollbars */
void Resized_Result ( whichWindow) /* Resized this window */
WindowPtr whichWindow; /* Window that was resized */
{
WindowPtr SavePort; /* Place to save the last port */
Rect temp2Rect; /* temp rectangle */
GetPort (&SavePort);
SetPort (Result_Window);
if (ScrollHHandle != NIL)
{
HLock ((Handle)ScrollHHandle);
HideControl (ScrollHHandle);
InvalRect (&(*ScrollHHandle)->contrlRect); /* Flag old position for update rout*/
MoveControl (ScrollHHandle, Result_Window->portRect.left-1,
Result_Window->portRect.bottom - 15);
SizeControl (ScrollHHandle, (Result_Window->portRect.right
- Result_Window->portRect.left) - 13, 16);
ShowControl (ScrollHHandle);
HUnlock ((Handle)ScrollHHandle);
}
if (ScrollVHandle != NIL)
{
HLock ((Handle)ScrollVHandle);
HideControl (ScrollVHandle);
InvalRect (&(*ScrollVHandle)->contrlRect); /* Flag old position for update rout*/
MoveControl (ScrollVHandle, Result_Window->portRect.right-15,
Result_Window->portRect.top-1);
SizeControl (ScrollVHandle, 16, (Result_Window->portRect.bottom
- Result_Window->portRect.top) - 13);
ShowControl (ScrollVHandle);
HUnlock ((Handle)ScrollVHandle);
}
InvalRect(&Result_Window->portRect);
DrawGrowIcon (Result_Window);
SetPort (SavePort);
}
/* End of function */
/* ====================================== */
/* Update our window, someone uncovered a part of us */
void UpDate_Result (whichWindow)
WindowPtr whichWindow;
{
WindowPtr SavePort; /* Place to save the last port */
GetPort (&SavePort); /* Save the current port */
SetPort (Result_Window); /* Set the port to my window */
InvalRect(&Result_Window->portRect);
BeginUpdate (Result_Window);
draw_result();
DrawControls (Result_Window); /* Draw all the controls */
DrawGrowIcon (Result_Window); /* Draw the Grow box */
EndUpdate ( Result_Window );
SetPort (SavePort); /* Restore the old port */
}
extern CGrafPtr proton_bmap;
extern Rect proton_rect;
extern short s1_off_top, s1_off_left;
extern CGrafPtr flourine_bmap;
extern Rect flourine_rect;
extern short s2_off_top, s2_off_left;
short src_changed; /* global: 1 if either source image has moved or changed, 0 otherwise */
static void draw_result()
{
Rect clipper;
short i;
Rect offrect;
GDHandle themaxdevice;
Point tempP;
Rect globRect;
clipper.top = Result_Window->portRect.top;
clipper.bottom = Result_Window->portRect.bottom - 15;
clipper.right = Result_Window->portRect.right - 15;
clipper.left = Result_Window->portRect.left;
ClipRect( &clipper );
EraseRect( &clipper );
if ( proton_bmap != NIL && flourine_bmap != NIL )
{
if ( src_changed )
{
tempP.v = Result_Window->portRect.top;
tempP.h = Result_Window->portRect.left;
LocalToGlobal(&tempP);
globRect.top = tempP.v;
globRect.left = tempP.h;
tempP.v = Result_Window->portRect.bottom;
tempP.h = Result_Window->portRect.right;
LocalToGlobal(&tempP);
globRect.bottom = tempP.v;
globRect.right = tempP.h;
themaxdevice = GetMaxDevice(&globRect);
add_bmaps( proton_bmap, &proton_rect, s1_off_top, s1_off_left,
flourine_bmap, &flourine_rect, s2_off_top, s2_off_left,
&result_bmap, &result_rect, themaxdevice ); /* deletes old result_bmap, returns new one */
src_changed = FALSE;
off_top = 0;
off_left = 0;
SetCtlValue (ScrollHHandle, min_scroll);
SetCtlValue (ScrollVHandle, min_scroll);
}
if ( result_bmap != NIL )
{
offrect = clipper;
offrect.top += off_top;
offrect.bottom += off_top;
if ( offrect.bottom > result_rect.bottom + off_top )
{
offrect.bottom = result_rect.bottom;
clipper.bottom = result_rect.bottom - off_top;
}
offrect.left += off_left;
offrect.right += off_left;
if ( offrect.right > result_rect.right + off_left )
{
offrect.right = result_rect.right;
clipper.right = result_rect.right - off_left;
}
HLock((Handle) (result_bmap->portPixMap));
CopyBits( *(result_bmap->portPixMap), &thePort->portBits,
&offrect, &clipper, (short) srcCopy,
(RgnHandle) NIL);
HUnlock((Handle) (result_bmap->portPixMap));
}
}
else
{
SetOrigin (off_left, off_top);
for ( i = 0; i < all_my_colors; i++)
{
PmForeColor( i );
MoveTo( 0, i );
LineTo( 300, i );
}
SetOrigin (0, 0);
}
ClipRect( &Result_Window->portRect );
}
/* End of UpDate */
/* =========================================== */
/* vertical scroll bar */
static void HandleVScrollBar (code, Start, Stop, Increment, LIncrement,
theControl, myPt)
short code; /* Selection code for part of scroll bar */
short Start; /* Minimum value the scroll bar can assume */
short Stop; /* Maximum value the scroll bar can assume */
short LIncrement, Increment; /* Increment to move when pressed in an*/
ControlHandle theControl; /* Handle to the scroll bar control */
Point myPt; /* Returned point from track the scrollbar */
{ /* Start of this function */
short theValue; /* Value of the scrollbar */
long MaxTick; /* Timer used for repeat scrolling */
do /* Do the scroll as long as the button is do*/
{ /* Timer used for repeat scrolling */
HiliteControl (theControl, code); /* Darken the arrow */
theValue = GetCtlValue (theControl); /* Get current state */
if (code == inUpButton) /* See if in the Up arrow */
{
theValue = theValue - Increment; /* Subtract the single d*/
if (theValue < Start) /* Check for boundary conditions */
theValue = Start; /* Pin at the start value */
}
if (code == inDownButton) /* See if in the Down arrow */
{
theValue = theValue + Increment; /* Add the single decrem*/
if (theValue > Stop) /* Check for boundary conditions */
theValue = Stop; /* Pin at the stop value */
}
if (code == inPageUp) /* See if in the up/left grey area */
{
theValue = theValue - LIncrement; /* Subtract the page inc*/
if (theValue < Start) /* Check for boundary conditions */
theValue = Start; /* Pin at the Start value */
}
if (code == inPageDown) /* See if in the down/right grey area */
{
theValue = theValue + LIncrement; /* Add the page incremen*/
if (theValue > Stop) /* Check for boundary conditions */
theValue = Stop; /* Pin at the Stop value */
}
if (code == inThumb) /* See if in the drag box area */
{
code = TrackControl (theControl, myPt, NIL); /* Let the O*/
theValue = GetCtlValue (theControl); /* Get current state*/
}
SetCtlValue (theControl, theValue); /* Set new state */
off_top = (short) ( (double)(result_rect.bottom - result_rect.top) * (double) theValue
/ (double) (Stop - Start) );
draw_result();
MaxTick = TickCount () + 9; /* Time delay for auto-scroll */
do /* Start of delay routine */
{ /* Spin on doing nothing */
} while ((Button () == TRUE) && (TickCount () <= MaxTick)); /* E*/
HiliteControl (theControl, 0); /* Lighten the arrow */
} /* End for StillDown */
while (StillDown () == TRUE); /* End for StillDown */
}
/* End for HandleVScrollBar */
/* ====================================================== */
/* horizontal scroll bar */
static void HandleHScrollBar (code, Start, Stop, Increment, LIncrement,
theControl, myPt)
short code; /* Selection code for part of scroll bar */
short Start; /* Minimum value the scroll bar can assume */
short Stop; /* Maximum value the scroll bar can assume */
short LIncrement, Increment; /* Increment to move when pressed in an*/
ControlHandle theControl; /* Handle to the scroll bar control */
Point myPt; /* Returned point from track the scrollbar */
{ /* Start of this function */
short theValue; /* Value of the scrollbar */
long MaxTick; /* Timer used for repeat scrolling */
do /* Do the scroll as long as the button is do*/
{ /* Timer used for repeat scrolling */
HiliteControl (theControl, code); /* Darken the arrow */
theValue = GetCtlValue (theControl); /* Get current state */
if (code == inUpButton) /* See if in the Up arrow */
{
theValue = theValue - Increment; /* Subtract the single d*/
if (theValue < Start) /* Check for boundary conditions */
theValue = Start; /* Pin at the start value */
}
if (code == inDownButton) /* See if in the Down arrow */
{
theValue = theValue + Increment; /* Add the single decrem*/
if (theValue > Stop) /* Check for boundary conditions */
theValue = Stop; /* Pin at the stop value */
}
if (code == inPageUp) /* See if in the up/left grey area */
{
theValue = theValue - LIncrement; /* Subtract the page inc*/
if (theValue < Start) /* Check for boundary conditions */
theValue = Start; /* Pin at the Start value */
}
if (code == inPageDown) /* See if in the down/right grey area */
{
theValue = theValue + LIncrement; /* Add the page incremen*/
if (theValue > Stop) /* Check for boundary conditions */
theValue = Stop; /* Pin at the Stop value */
}
if (code == inThumb) /* See if in the drag box area */
{
code = TrackControl (theControl, myPt, NIL); /* Let the O*/
theValue = GetCtlValue (theControl); /* Get current state*/
}
SetCtlValue (theControl, theValue); /* Set new state */
off_left = (short) ( (double)(result_rect.bottom - result_rect.top) * (double) theValue
/ (double) (Stop - Start) );
draw_result();
MaxTick = TickCount () + 9; /* Time delay for auto-scroll */
do /* Start of delay routine */
{ /* Spin on doing nothing */
} while ((Button () == TRUE) && (TickCount () <= MaxTick)); /* E*/
HiliteControl (theControl, 0); /* Lighten the arrow */
} /* End for StillDown */
while (StillDown () == TRUE); /* End for StillDown */
}
/* End for HandleHScrollBar */
static void Do_A_ScrollBar (code, theControl, myPt) /* Handle a ScrollBa*/
short code; /* Which place in scrollbar was pressed */
ControlHandle theControl; /* Which place in scrollbar was pressed */
Point myPt; /* Where the scrollbar was pressed */
{ /* Start of a ScrollBar being pressed */
short RefCon;
RefCon = GetCRefCon (theControl); /* get control refcon */
switch (RefCon) /* Select correct scrollbar */
{ /*Start correct scrollbar */
case I_Vertical_Scroll_bar: /* Vertical Scroll bar, scroll bar */
HandleVScrollBar (code, min_scroll, max_scroll, small_step, large_step, theControl, myPt); /* c*/
break; /* End for handling a scroll bar */
case I_Horiz_Scroll_bar: /* Horiz Scroll bar, scroll bar */
HandleHScrollBar (code, min_scroll, max_scroll, small_step, large_step, theControl, myPt); /* c*/
break; /* End for handling a scroll bar */
default: /* allow other scrollbars (lists), trap for */
break; /* end of default */
} /* end of switch */
}
/* Handle a ScrollBar being pressed */
/* ================================= */
/* Open our window and draw everything */
void Open_Result ()
{
short Index;
Rect dataBounds;
Point cSize;
if (Result_Window == NIL)
{
/* Result_Window = (WindowPtr) GetNewCWindow (10, NIL, (WindowPtr) - 1); -- Get the w*/
tempRect.top = 139;
tempRect.bottom = 334;
tempRect.left = 399;
tempRect.right = 590;
Result_Window = (WindowPtr) NewCWindow( (Ptr) NIL, &tempRect, "\pResult",
(Boolean) true, 8, (WindowPtr)-1, (Boolean) false, 10L);
/* MoveWindow (Result_Window, tempRect.left, tempRect.top, TRUE); */
SetPort (Result_Window);
/* Make a scroll bar, Vert Scroll bar */
ScrollVHandle = GetNewControl (I_Vertical_Scroll_bar, Result_Window);
/* Make a scroll bar, Horiz Scroll bar */
ScrollHHandle = GetNewControl (I_Horiz_Scroll_bar, Result_Window);
ShowWindow (Result_Window);
SelectWindow (Result_Window);
/* SetPalette( Result_Window, mypalette, true); */
/* RGBBackColor(&whiteRGB); */
/* RGBForeColor(&BlackRGB); -- copybits usually expect black fore and white back */
/* OpColor(&grayRGB); */
Resized_Result (Result_Window);
}
else
{
SelectWindow (Result_Window); /* Already open, so show it */
}
}
/* End of open function */
/* ================================= */
/* Handle action to our window, like controls */
void Do_Result (myEvent)
EventRecord *myEvent;
{
short RefCon; /* RefCon for controls */
short code; /* Location of event in window or controls */
short theValue; /* Current value of a control */
WindowPtr whichWindow; /* Window pointer where event happened */
Point myPt; /* Point where event happened */
ControlHandle theControl; /* Handle for a control */
WindowPtr SavePort;
/* Start of Window handler */
if (Result_Window != NIL) /* Handle only when the window is valid */
{
GetPort (&SavePort);
SetPort(Result_Window);
SetOrigin(0, 0);
code = FindWindow (myEvent->where, &whichWindow); /* Get where*/
if ((myEvent->what == mouseDown) && (Result_Window == whichWindow))
{
myPt = myEvent->where; /* Get mouse position */
GlobalToLocal (&myPt); /* Make it relative */
}
if ((Result_Window == whichWindow) && (code == inContent)) /* for o*/
{
code = FindControl (myPt, whichWindow, &theControl); /* G*/
if ((code == inUpButton) || (code == inDownButton)
|| (code == inThumb) || (code == inPageDown)
|| (code == inPageUp))
Do_A_ScrollBar (code, theControl, myPt); /* Do scroll*/
if (code != 0) /* Check type of control */
code = TrackControl (theControl, myPt, NIL); /* Track*/
} /* End for if (Result_Window==whichWindow) */
} /* End for if (Result_Window != NIL) */
SetPort(SavePort);
}
/* End of function */
/* ================================= */
void save_result()
/* saves results PICT2 to a PICT file -- called when SAVE PICT menu item chosen */
{
/* check to see if there is a result-pict
if not, then beep
else
put up save files dialog
if not cancelled then
open a new PICT file
write 512-byte empty header
write the PICT from the Handle to the file
end if
end if
*/
}
void copy_result()
/* copys a PICT from the result pixmap into the clipboard */
{
short err;
if ( result_pic != NIL )
{
HLock( (Handle) result_pic );
err = PutScrap( GetHandleSize( (Handle)result_pic ), 'PICT', *result_pic);
HUnlock( (Handle) result_pic );
}
}
void cut_result()
/* copys a PICT from the result pixmap into the clipboard, and then clears the pixmap */
{
}
void clear_result()
{
}
void crop_result()
{
}